import {
  Store as VuexStore,
  CommitOptions,
  DispatchOptions,
  Module
} from 'vuex'
import state from './state'
import mutations, {
  PermissionMutations,
  PermissionMutationTypes
} from './mutations'
import actions, { PermissionActions, permissionActionTypes } from './actions'
import type { PermissionState } from './state'
import { RootState } from '@/store'

export { PermissionState, PermissionMutationTypes, permissionActionTypes }

export type PermissionStore<U = PermissionState> = Omit<
  VuexStore<U>,
  'getters' | 'commit' | 'dispatch'
> & {
  commit<
    K extends keyof PermissionMutations,
    P extends Parameters<PermissionMutations[K]>[1]
  >(
    key: K,
    payload: P,
    options?: CommitOptions
  ): ReturnType<PermissionMutations[K]>
} & {
  dispatch<K extends keyof PermissionActions>(
    key: K,
    payload: Parameters<PermissionActions[K]>[1],
    options?: DispatchOptions
  ): ReturnType<PermissionActions[K]>
}

export const permissionStore: Module<PermissionState, RootState> = {
  state,
  mutations,
  actions: actions as any
}
